import { JSEncrypt } from 'jsencrypt'
import { publicKey } from '../keys';

// 加密数据函数
export function encryptedData(data: string) {
  const enc = new JSEncrypt();
  enc.setPublicKey(publicKey)
  return enc.encrypt(data) as string
}

// 日期转化汉子
export function formatTimeToChinese(time: number) {
  const currentTime = new Date().getTime();
  const result = (currentTime - time);

  const secends = Math.floor(result / 1000 % 60)
  const minute = Math.floor(result / 1000 / 60 % 60)
  const hour = Math.floor(result / 1000 / 60 / 60 % 24)
  const date = Math.floor(result / 1000 / 60 / 60 / 24 % 30)
  const month = Math.floor(result / 1000 / 60 / 60 / 24 / 30 % 12)
  const year = Math.floor(result / 1000 / 60 / 60 / 24 / 30 / 12)

  if (year) return year + '年前';
  if (month) return month + '月前';
  if (date) return date + '天前';
  if (hour) return hour + '小时前';
  if (minute) return minute + '分钟前';
  if (secends) return secends + '秒前';

}


// 添加类名函数
export function addClassName(style, ...className: string[]) {
  return className.map(v => style[v]).join(' ')
}